package com.spic.business.riskbase.hierarchy.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.spic.common.core.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.spic.business.riskbase.hierarchy.domain.RiskDetailsInfo;
import com.spic.business.riskbase.hierarchy.mapper.RiskAnalyseMapper;
import com.spic.business.riskbase.hierarchy.domain.RiskAnalyse;
import com.spic.business.riskbase.hierarchy.service.IRiskAnalyseService;

/**
 * analyseService业务层处理
 *
 * @author ruoyi
 * @date 2023-04-14
 */
@Service
public class RiskAnalyseServiceImpl implements IRiskAnalyseService
{
    @Autowired
    private RiskAnalyseMapper riskAnalyseMapper;

    /**
     * 查询analyse
     *
     * @param id analyse主键
     * @return analyse
     */
    @Override
    public RiskAnalyse selectRiskAnalyseById(Long id)
    {
        return riskAnalyseMapper.selectRiskAnalyseById(id);
    }

    /**
     * 查询analyse列表
     *
     * @param riskAnalyse analyse
     * @return analyse
     */
    @Override
    public List<RiskAnalyse> selectRiskAnalyseList(RiskAnalyse riskAnalyse)
    {
        return riskAnalyseMapper.selectRiskAnalyseList(riskAnalyse);
    }

    /**
     * 新增analyse
     *
     * @param riskAnalyse analyse
     * @return 结果
     */
    @Transactional
    @Override
    public int insertRiskAnalyse(RiskAnalyse riskAnalyse)
    {
        int rows = riskAnalyseMapper.insertRiskAnalyse(riskAnalyse);
        insertRiskDetailsInfo(riskAnalyse);
        return rows;
    }

    /**
     * 修改analyse
     *
     * @param riskAnalyse analyse
     * @return 结果
     */
    @Transactional
    @Override
    public int updateRiskAnalyse(RiskAnalyse riskAnalyse)
    {
        riskAnalyseMapper.deleteRiskDetailsInfoByRiskAnalyseId(riskAnalyse.getId());
        insertRiskDetailsInfo(riskAnalyse);
        return riskAnalyseMapper.updateRiskAnalyse(riskAnalyse);
    }

    /**
     * 批量删除analyse
     *
     * @param ids 需要删除的analyse主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteRiskAnalyseByIds(Long[] ids)
    {
        riskAnalyseMapper.deleteRiskDetailsInfoByRiskAnalyseIds(ids);
        return riskAnalyseMapper.deleteRiskAnalyseByIds(ids);
    }

    /**
     * 删除analyse信息
     *
     * @param id analyse主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteRiskAnalyseById(Long id)
    {
        riskAnalyseMapper.deleteRiskDetailsInfoByRiskAnalyseId(id);
        return riskAnalyseMapper.deleteRiskAnalyseById(id);
    }

    @Override
    public int deleteRiskAnalyseByRiskDescription(Long id) {
        return riskAnalyseMapper.deleteRiskAnalyseByRiskDescription(id);
    }

    @Override
    public int batchRiskAnalyse(List<RiskAnalyse> list) {
        return riskAnalyseMapper.batchRiskAnalyse(list);
    }

    /**
     * 新增${subTable.functionName}信息
     *
     * @param riskAnalyse analyse对象
     */
    public void insertRiskDetailsInfo(RiskAnalyse riskAnalyse)
    {
        List<RiskDetailsInfo> riskDetailsInfoList = riskAnalyse.getRiskDetailsInfoList();
        Long id = riskAnalyse.getId();
        if (StringUtils.isNotNull(riskDetailsInfoList))
        {
            List<RiskDetailsInfo> list = new ArrayList<RiskDetailsInfo>();
            for (RiskDetailsInfo riskDetailsInfo : riskDetailsInfoList)
            {
                riskDetailsInfo.setRiskAnalyseId(id);
                list.add(riskDetailsInfo);
            }
            if (list.size() > 0)
            {
                riskAnalyseMapper.batchRiskDetailsInfo(list);
            }
        }
    }
}
